package yl.hs.bmipfull.controllers.production;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.production.IViolationReportService;
import yl.hs.bmipfull.service.system.ISearchViewService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/*
 * ViolationReportController
 * @category
 * @author 谢景广
 * @date 2023-03-23
 */
@RestController
@Api(value = "违规上报数据Web接口", tags = "生产管理——工地违规上报数据")
@RequestMapping("/api/production/project/violation")
public class ViolationReportController extends ControllerBase {
    @ApiOperation(value = "上报违规信息",notes = "上报违规信息")
    @PostMapping("/save")
    public WebResult saveViolation(@RequestBody SubmitModel model){
        try {
            var result = service.save(model);
            if(result> 0) {
                return success("数据已保存");
            }
            else{
                return fail("保存失败");
            }
        }
        catch (Exception ee){
            return error(ee);
        }
    }

    @ApiOperation(value = "分页查询上报违规信息",notes = "分页查询上报违规信息")
    @PostMapping("/query/{rowNum}/{page}")
    public WebResult saveViolation(@RequestBody PageQuery query, @PathVariable Integer rowNum,@PathVariable Integer page){
        try {
            var result = service.queryPage(query,rowNum,page);
            svSVC.updateUserMenuView(query);
            return success("ok",result);
        }
        catch (Exception ee){
            return error(ee);
        }
    }

    @Autowired
    public void setService(IViolationReportService service) {
        this.service = service;
    }

    @Autowired
    public void setSvSVC(ISearchViewService svSVC) {
        this.svSVC = svSVC;
    }

    private IViolationReportService service;
    private ISearchViewService svSVC;
}
